﻿using System.Linq;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure; 

namespace BusinessStorage
{
    public partial class OuSuisJeService : TableServiceContext
    {
        #region Constructor
        public OuSuisJeService(string baseAddress, StorageCredentials credentials)
            : base(baseAddress, credentials)
        {

        }
        #endregion

        #region Entity Set
        public IQueryable<Enigma> Enigmas
        {
            get
            {
                return new CloudTableQuery<Enigma>(this.CreateQuery<Enigma>("Enigmas"));
            }
            
        }

        public IQueryable<User> Users
        {
            get { return new CloudTableQuery<User>(this.CreateQuery<User>("Users")); }
        }

        public IQueryable<Response> Responses
        {
            get { return new CloudTableQuery<Response>(this.CreateQuery<Response>("Responses")); }
        }
        #endregion

        #region CRUD Operation
        #region Insert Operation
        public void AddEnigma(Enigma enigma)
        {
            this.AddObject("Enigmas", enigma);
            this.SaveChanges();
        }

        public void AddUser(User user)
        {
            this.AddObject("Users", user);
            this.SaveChanges();
        }

        public void AddResponse(Response response)
        {
            this.AddObject("Responses", response);
            this.SaveChanges();
        }
        #endregion
        #region Update Operation
        public void UpdateEnigma(Enigma enigma)
        {
            this.AttachTo("Enigmas", enigma, "*");
            this.UpdateObject(enigma);
            this.SaveChanges();
        }

        public void UpdateUser(User user)
        {
            this.AttachTo("Users", user, "*");
            this.UpdateObject(user);
            this.SaveChanges();
        }

        public void UpdateResponse(Response response)
        {
            this.AttachTo("Responses", response, "*");
            this.UpdateObject(response);
            this.SaveChanges();
        }
        #endregion
        #region Delte Operation
        public void DeleteEnigma(Enigma enigma)
        {
            this.AttachTo("Enigmas", enigma, "*");
            this.DeleteObject(enigma);
            this.SaveChanges();
        }

        public void DeleteUser(User user)
        {
            this.AttachTo("Users", user, "*");
            this.DeleteObject(user);
            this.SaveChanges();
        }

        public void DeleteResponse(Response response)
        {
            this.AttachTo("Responses", response, "*");
            this.DeleteObject(response);
            this.SaveChanges();
        }
        #endregion
        #endregion

    }
}
